﻿using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine;

public class TitleScript : MonoBehaviour {
    private bool hasBegin;
    public UnityEngine.UI.Image Image;
    public List<Sprite> SpriteList;

    private float lastUpdateTime;
    int mIndex = 0;

    void Start()
    {
    }

    void Update()
    {
        if(Time.time - lastUpdateTime > 0.5f)
        {
            mIndex = 1 - mIndex;
            Image.sprite = SpriteList[mIndex];
            lastUpdateTime = Time.time;
        }
    }

    void LateUpdate()
    {
        if (GameApp.GetInstance() != null)
        {
            if (GameApp.GetInstance().GetPhase() != EGamePhase.TITLE)
            {
                this.gameObject.SetActive(false);
                return;
            }
        }
        if (hasBegin == false)
        {
            foreach (KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
            {
                if (Input.GetKeyDown(kcode))
                {
                    hasBegin = true;
                    this.gameObject.SetActive(false);
                    GameApp.GetInstance().TrySkipTitle();
                    GameObject.Find("AudioSource").GetComponent<AudioSource>().Play();
                    return;
                }
            }
        }
    }
}
